<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:au="http://java.sun.com/jsf/composite/autocomplete">

    <ui:define name="content">
        <h:form>
            <p:panel header="Shift Amendment Slip">
                <p:panel >
                    <h:panelGrid columns="2">
                        <p:panel>
                            <p:panel header="Employee Details">
                                <p:panelGrid columns="2">
                                    <h:outputLabel value="Form Number"/>
                                    <p:inputText value="#{staffAmendmentFormController.currAmendmentForm.code}"/>
                                    <h:outputLabel value="From Staff"/>
                                    <au:completeStaff value="#{staffAmendmentFormController.currAmendmentForm.fromStaff}"/>                                 
                                    <h:outputLabel value="From Date "/>
                                    <p:calendar id="formDate" value="#{staffAmendmentFormController.currAmendmentForm.fromDate}"
                                                pattern="yyyy MM dd HH:mm:ss">
                                    </p:calendar>   
                                    <p:commandButton ajax="false" value="Process Staff Shift" 
                                                    action="#{staffAmendmentFormController.fetchFromStaffShift()}" />
                                    <h:panelGroup>
                                        <p:selectOneMenu value="#{staffAmendmentFormController.currAmendmentForm.fromStaffShift}"   >
                                            <f:selectItem itemLabel="Select Staff Shift 1"/>
                                            <f:selectItems value="#{staffAmendmentFormController.fromStaffShifts}"
                                                           var="itm" itemLabel="#{itm.shift.name}" itemValue="#{itm}" />
                                        </p:selectOneMenu>
                                        <p:selectOneMenu value="#{staffAmendmentFormController.currAmendmentForm.fromStaffShiftSecond}"   >
                                            <f:selectItem itemLabel="Select Staff Shift 2"/>
                                            <f:selectItems value="#{staffAmendmentFormController.fromStaffShifts}"
                                                           var="itm" itemLabel="#{itm.shift.name}" itemValue="#{itm}" />
                                        </p:selectOneMenu>
                                    </h:panelGroup>
                                </p:panelGrid>
                            </p:panel>
                            <p:panel header="Action Employee Details">
                                <p:panelGrid columns="2">
                                    <h:outputLabel value="To Staff "/>
                                    <au:completeStaff value="#{staffAmendmentFormController.currAmendmentForm.toStaff}"/>                                                        
                                    <h:outputLabel value="To Date "/>
                                    <p:calendar id="toDate" value="#{staffAmendmentFormController.currAmendmentForm.toDate}"
                                                pattern="yyyy MM dd HH:mm:ss">

                                    </p:calendar>                                                                                              
                                    <p:commandButton ajax="false" value="Process Shift" 
                                                    action="#{staffAmendmentFormController.fetchToShift()}" />
                                    <h:panelGroup>
                                        <p:selectOneMenu value="#{staffAmendmentFormController.currAmendmentForm.toShift}"   >
                                            <f:selectItem itemLabel="Select Shift 1"/>
                                            <f:selectItems value="#{staffAmendmentFormController.toShifts}"
                                                           var="itm" itemLabel="#{itm.name}" itemValue="#{itm}" />
                                        </p:selectOneMenu>
                                        <p:selectOneMenu value="#{staffAmendmentFormController.currAmendmentForm.toShiftSecond}"   >
                                            <f:selectItem itemLabel="Select Shift 2"/>
                                            <f:selectItems value="#{staffAmendmentFormController.toShifts}"
                                                           var="itm" itemLabel="#{itm.name}" itemValue="#{itm}" />
                                        </p:selectOneMenu>
                                    </h:panelGroup>
                                </p:panelGrid> 
                            </p:panel>
                            <p:panel>
                                <p:panelGrid columns="2">
                                    <h:outputLabel value="Approved Person"/>
                                    <au:completeStaff value="#{staffAmendmentFormController.currAmendmentForm.approvedStaff}"/>                                   
                                    <h:outputLabel value="Approved Date"/>
                                    <p:calendar id="approvedDate" value="#{staffAmendmentFormController.currAmendmentForm.approvedAt}"
                                                pattern="dd MMMM yyyy" >
                                    </p:calendar>
                                    <h:outputLabel value="Comment"/>
                                    <p:inputTextarea value="#{staffAmendmentFormController.currAmendmentForm.comments}" />
                                    <p:commandButton id="btnAdd" ajax="false" value="Save" 
                                                    action="#{staffAmendmentFormController.saveAmendmentForm()}"/>

                                    <p:commandButton ajax="false" value="Clear" action="#{staffAmendmentFormController.clear()}"/>
                                    <p:commandButton value="Delete" action="#{staffAmendmentFormController.deleteAmmendmentForm}" ajax="false"></p:commandButton>
                                </p:panelGrid>
                            </p:panel>
                        </p:panel>
                        <p:panel header="Search Forms">
                            <h:panelGrid columns="2">
                                <h:outputLabel value="From Date"/>
                                <p:calendar value="#{staffAmendmentFormController.fromDate}"
                                            pattern="yyyy MM dd HH:mm:ss" >
                                </p:calendar>
                                <h:outputLabel value="To Date"/>
                                <p:calendar id="forDateS" value="#{staffAmendmentFormController.toDate}"
                                            pattern="yyyy MM dd HH:mm:ss" >
                                </p:calendar>
                                <h:outputLabel value="Staff : "/>
                                <au:completeStaff value="#{staffAmendmentFormController.fromStaff}"/>                                                                 
                                <h:outputLabel value="Action Staff : "/>
                                <au:completeStaff value="#{staffAmendmentFormController.toStaff}"/>                                                                    
                                <h:outputLabel value="Approved Person"/>
                                <au:completeStaff value="#{staffAmendmentFormController.approvedStaff}"/>                                                                   
                                <p:commandButton ajax="false" value="Search Created Date" action="#{staffAmendmentFormController.createAmmendmentTable()}" />
                                <p:commandButton ajax="false" value="Search Approved Date" action="#{staffAmendmentFormController.createAmmendmentTableApprovedDate()}" />
                            </h:panelGrid>
                            <p:dataTable value="#{staffAmendmentFormController.amendmentForms}" var="add" 
                                         rowStyleClass="#{add.retired eq true ? 'redText':''}"
                                         scrollable="true"
                                         scrollHeight="400">
                                <p:column headerText="View" >
                                    <p:commandButton ajax="false" value="View" 
                                                    action="#{staffAmendmentFormController.viewAmendmentForm(add)}" disabled="#{add.retired}"></p:commandButton>
                                </p:column>
                                <p:column headerText="Staff">
                                    <p:outputLabel value="#{add.fromStaff.person.nameWithTitle}" ></p:outputLabel>
                                </p:column>
                                <p:column headerText="Staff Time">
                                    <p:outputLabel value="#{add.fromDate}" >
                                        <f:convertDateTime pattern="yyyy MM dd HH:mm:ss" />
                                    </p:outputLabel>
                                </p:column>
                                <p:column headerText="Action Staff">
                                    <p:outputLabel value="#{add.toStaff.person.nameWithTitle}" ></p:outputLabel>
                                </p:column>
                                <p:column headerText="Action Staff Time">
                                    <p:outputLabel value="#{add.toDate}" >
                                        <f:convertDateTime pattern="yyyy MM dd HH:mm:ss" />
                                    </p:outputLabel>
                                </p:column>
                                <p:column headerText="Aproved By">
                                    <p:outputLabel value="#{add.approvedStaff.person.nameWithTitle}" ></p:outputLabel>
                                </p:column>
                                <p:column headerText="Comment">
                                    <p:outputLabel value="#{add.comments}" ></p:outputLabel>
                                </p:column>
                                <p:column headerText="Creater">
                                    <p:outputLabel value="#{add.creater.webUserPerson.nameWithTitle}" ></p:outputLabel>
                                    <br></br>
                                    <p:outputLabel value="Deleted By  #{add.retirer.webUserPerson.nameWithTitle}" rendered="#{add.retired}" style="color: blue;"></p:outputLabel>
                                </p:column>
                            </p:dataTable>
                        </p:panel>
                    </h:panelGrid>

                </p:panel>
            </p:panel>
        </h:form>
    </ui:define> 

</ui:composition>
